﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BLL_NhaSach;
using DAL_NhaSach;

namespace AppQlyNhaSach.PhieuNhap
{
    public partial class frmCTPhieuNhap : DevExpress.XtraEditors.XtraForm
    {
        CTPhieuNhapBLL ctBLL;
        PhieuNhapBLL pnBLL;
        public frmCTPhieuNhap()
        {
            InitializeComponent();
        }

        private void frmCTPhieuNhap_FormClosing(object sender, FormClosingEventArgs e)
        {
            frmMainNS.isCTPhieuNhap = false;
        }

        private void frmCTPhieuNhap_Load(object sender, EventArgs e)
        {
            ctBLL = new CTPhieuNhapBLL(Properties.Settings.Default.ConnectionStringUser);
            grdCTPhieuNhap.DataSource = ctBLL.getAllData();
            pnBLL = new PhieuNhapBLL(Properties.Settings.Default.ConnectionStringUser);
            gridView1.FocusedRowHandle = 0;
        }

        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            try
            {
                int id =int.Parse(gridView1.GetFocusedRowCellValue("MaPhieuNhap").ToString());
                DAL_NhaSach.PhieuNhap pns = (DAL_NhaSach.PhieuNhap)pnBLL.findObject(id);
                txtNgay.Text = pns.NgayNhap.ToShortDateString();
                txtNCC.Text = pns.NhaCungCap.TenNCC;
                txtNhanVien.Text = pns.NhanVien.HoTen;
                DAL_NhaSach.ChiTietPhieuNhap ctpn = (DAL_NhaSach.ChiTietPhieuNhap)ctBLL.findObjects(id);
                txtMa.Text = ctpn.MaPhieuNhap.ToString();
                txtTen.Text = ctpn.Sach.TenSach;
                txtSoLuong.Text = ctpn.SoLuong.ToString();
                txtDonGia.Text = ctpn.DonGia.ToString();
               
            }
            catch { }
        }
    }
}